package top.lixunda.ecommerce.server.good.api.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.LogGoodPriceDO;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author Xumda
 * @version time:2020/1/15 14:12
 */
@SuppressWarnings("WeakerAccess")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class LogGoodPriceVO {

    /**
     * 唯一自动增长id
     */
    private Integer id;

    /**
     * 商品Id
     */
    private Integer goodId;

    /**
     * 商品名称
     */
    private String goodName;

    /**
     * 商品分类id
     */
    private Integer subGoodId;

    /**
     * 商品分类名称
     */
    private String subGoodName;

    /**
     * 价格更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 更新的价格
     */
    private BigDecimal price;

    /**
     * 备注，可以是删除理由，用户申诉理由
     */
    private String remark;

    /**
     * 数据转换
     *
     * @param logGoodPriceDO LogGoodPriceDO
     * @return LogGoodPriceVO
     */
    public static LogGoodPriceVO fromLogGoodPriceDO(LogGoodPriceDO logGoodPriceDO) {
        if (ObjectValidators.isEmpty(logGoodPriceDO)) {
            return null;
        }
        LogGoodPriceVO logGoodPriceVO = new LogGoodPriceVO();
        BeanUtils.copyProperties(logGoodPriceDO, logGoodPriceVO);
        return logGoodPriceVO;
    }

    public static List<LogGoodPriceVO> fromLogGoodPriceDO(List<LogGoodPriceDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(LogGoodPriceVO::fromLogGoodPriceDO)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

}
